package com.holi.hiteacher.activity;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.view.View;
import android.widget.Button;

import com.holi.hiteacher.R;
import com.holi.hiteacher.bean.JsonResult;
import com.holi.hiteacher.net.ServiceGenerator;
import com.holi.hiteacher.net.api.UserService;
import com.holi.hiteacher.utils.ToastMaster;

import butterknife.BindView;
import butterknife.ButterKnife;
import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;

public class SignInDialogAty extends AppCompatActivity implements View.OnClickListener {
    @BindView(R.id.btnSign)
    Button btnSign;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_sign_in_dialog_aty);
        ButterKnife.bind(this);

        btnSign.setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        UserService service = ServiceGenerator.createService(UserService.class);
        Call<JsonResult> call = service.getSignInResult();
        call.enqueue(new Callback<JsonResult>() {
            @Override
            public void onResponse(Call<JsonResult> call, Response<JsonResult> response) {
                JsonResult ret = response.body();
                if (ret == null) {
                } else {
                    Log.w("joshua", "onResponse: " + ret.isResult());
                    ToastMaster.showToast(SignInDialogAty.this, "签到成功！");
                    SignInDialogAty.this.finish();
                }
            }

            @Override
            public void onFailure(Call<JsonResult> call, Throwable t) {
            }
        });
    }
}
